Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appcd-util

Package Overview
Dependencies
Maintainers
3
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appcd-util

Various utility functions to support the Appc Daemon.

  • 1.1.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
increased by25.96%
Maintainers
3
Weekly downloads
 
Created
Source

appcd-util

Common utility functions.

Visit https://github.com/appcelerator/appc-daemon for more information.

Installation

npm i appcd-util

Usage

import { arch } from 'appcd-util';

console.log(arch()); // 'x86' or 'x64'
import { arrayify } from 'appcd-util';

console.log(arrayify('foo')); // [ 'foo' ]

console.log(arrayify([ 'a', '', null, 'b' ], true)); // [ 'a', 'b' ]
import { assertNodeEngineVersion } from 'appcd-util';

// throw an exception if current node version doesn't satisfy the `engines.node` version
assertNodeEngineVersion(require('package.json'));
import { cache } from 'appcd-util';

const now = () => Date.now();

const first = await cache('my namespace', now);
const second = await cache('my namespace', now);
assert(first === second);

const third = await cache('my namespace', true, now);
assert(first !== third && second !== third);
import { cacheSync } from 'appcd-util';

const now = () => Date.now();

const first = cacheSync('my namespace', now);
const second = cacheSync('my namespace', now);
assert(first === second);

const third = cacheSync('my namespace', true, now);
assert(first !== third && second !== third);

Debouncer that returns a promise and that can be cancelled.

import { debounce } from 'appcd-util';

const fn = debounce(() => {
	console.log(new Date());
});

// schedule the callback to be called in 200ms
fn().then(() => {
	console.log('Function called');
});

// cancel the debounce
fn.cancel();
import { formatNumber } from 'appcd-util';

console.log(formatNumber(12)); // 12
console.log(formatNumber(123)); // 123
console.log(formatNumber(1234)); // 1,234
console.log(formatNumber(12345)); // 12,345
console.log(formatNumber(123456)); // 123,456
console.log(formatNumber(1234567)); // 1,234,567
import { get } from 'appcd-util';

const obj = {
	foo: 'bar'
};

console.log(get(obj, 'foo')); // 'bar'
console.log(get(obj, 'baz', 'pow')); // 'pow'

Get all open sockets, [net] servers, timers, child processes, filesystem watchers, and other handles.

import { getActiveHandles } from 'appcd-util';

console.log(getActiveHandles());
import { inherits } from 'appcd-util';

class A {}
class B extends A {}
class C {}

console.log(inherits(B, A)); // true
console.log(inherits(B, C)); // false
import { mergeDeep } from 'appcd-util';

const obj1 = {
	a: {
		b: 'c'
	}
};

const obj2 = {
	a: {
		d: 'e'
	}
};

console.log(mergeDeep(obj1, obj2)); // { a: { b: 'c', d: 'e' } }
import { mutex } from 'appcd-util';

const fn = () => {
	return mutex('my mutex', () => {
		console.log('foo!');
	});
};

await Promise.all([ fn(), fn(), fn() ]);
import { randomBytes } from 'appcd-util';

console.log(randomBytes(20));
import { sha1 } from 'appcd-util';

console.log(sha1('foo'));
import { sleep } from 'appcd-util';

await sleep(1000); // sleep for 1 second

Block multiple simultaneous callers until the first caller finishes, then all queued up 'tailgaters' are resolved with the result.

import { tailgate } from 'appcd-util';

const fn = () => {
	return tailgate('my tailgate', () {
		console.log('I will only be called once');
	});
};

await Promise.all([ fn(), fn(), fn() ]);
import { unique } from 'appcd-util';

console.log(unique([ 'a', 'b', 'a', 'b' ])); // [ 'a', 'b' ]

This project is open source under the Apache Public License v2 and is developed by Axway, Inc and the community. Please read the LICENSE file included in this distribution for more information.

FAQs

Package last updated on 04 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc